/**
 * yeahmobi.com Inc.
 * Copyright © 2014 YeahMobi | All Rights Reserved.
 */   
    
package com.ndp.fb.fbagent.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.ndp.fb.fbagent.service.AdImageFBService;
import com.ndp.fb.model.fbagent.param.APIPriority;
import com.ndp.fb.model.fbagent.param.ApiCallBackTarget;
import com.ndp.fb.model.fbagent.param.FacebookParam;
import com.restfb.Parameter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Title: AdImageFBServiceImpl.java
 * @Copyright: Copyright © 2015
 * @Description: 
 * @Company: yeahmobi
 * @Created on 下午2:25:39
 * @author giser.yang
 */
@Service
public class AdImageFBServiceImpl extends AbstractFBagentService implements AdImageFBService {
    static String fields = "account_id,created_time,hash,creatives,url,url_128,height,original_height,original_width,width,permalink_url,name,updated_time,id,status";

    /** 
     * @discription
     * @author giser.yang       
     * 创建时间 2015年7月16日 下午5:14:29           
     * @see com.ndp.fb.fbagent.service.AdImageFBService#getAdImages()     
     */  
        
    @Override
    public void getAdImages(FacebookParam adImageParam) {
        adImageParam.setFields(fields);
        adImageParam.setLimit(1000);
        adImageParam.setCallBack(true);
        adImageParam.setApiPriorityCode(APIPriority.FetchAdImageBusiness.getCode());
        adImageParam.setApiCallbackTargetType(ApiCallBackTarget.PublishResource.FetchAdImage.getTargetType());
//        adImageParam.setResultClassName(FbAdImage.class.getName());

        Map<String, String> equipment = new HashMap<String, String>();
        equipment.put("entrustAccountId", ""+adImageParam.getFbAccountId());
        equipment.put("accessToken", adImageParam.getAccessToken());
        equipment.put("lastupdatedtime", String.valueOf(adImageParam.getLastUpdatedTime()));
        adImageParam.setEquipment(equipment);
        List<Parameter> parameterList = adapter(adImageParam,false);
        String uri = "/act_" + adImageParam.getFbAccountId() + "/adimages";
        makeGetRequest(uri, adImageParam.getAccessToken(), parameterList.toArray(new Parameter[]{}));
    }
}
